package sis.ra.yahoor.result;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import sis.ra.utility.Utils;


public class companyProductVerbDistance {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String verbfile="C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.verbv2";
		String content=Utils.readFile(verbfile);
		String [] lines=content.split("\n");
		int count=0;
		HashMap<String,ArrayList<verbsnippet>> index=new HashMap<String,ArrayList<verbsnippet>>();
		HashMap<String, String> verboffset=new HashMap<String, String> ();
		for (int i=0;i<lines.length;i++)
		{
			if (lines[i].split("\t").length<2) continue;
			System.out.println(lines[i]);
//			String verb=lines[i].split("\t")[1];
//			String stemmedverb=extractPattern.stem(verb);
//			String sentence=lines[i].substring(lines[i].indexOf("==>"));
////			System.out.println(sentence);
//			int start=sentence.indexOf("COMPANY");
//			int end=sentence.indexOf("PRODUCT");
////			System.out.println(start+" "+end);
//			if (start>end)
//			{
//				 end=sentence.indexOf("COMPANY");
//				 start=sentence.indexOf("PRODUCT");
//			}
////			System.out.println(start+" "+end);
//			String partsent=sentence.substring(start,end+7);
//			String [] t=partsent.split(" ");
//			System.out.println(t.length+"\t"+stemmedverb+"\t"+verb+"\t"+partsent+"\t"+sentence);
//			Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.verbv1", t.length+"\t"+stemmedverb+"\t"+verb+"\t"+partsent+"\t"+sentence,true,true);
//			verbsnippet(String offset, String patsent, String sentence,	String verb, String verbinSent) {
			
			
			String  [] ts=lines[i].split("\t");
			String offset=ts[0];
			String productoffset=ts[1];
			String stemmedverb=ts[2];
			
	//		verbsnippet vs=new verbsnippet(offset,stemmedverb,"","","");
			verbsnippet vs=new verbsnippet(productoffset,stemmedverb,"","","");
			if (verboffset.keySet().contains(stemmedverb))
			{
				String line=verboffset.get(stemmedverb);
				String freq=line.split("\t")[0];
				String cummulateoffset=line.split("\t")[1];
				freq=Integer.parseInt(freq)+1+"";
				cummulateoffset=Integer.parseInt(cummulateoffset)+Integer.parseInt(productoffset)+"";
				verboffset.remove(stemmedverb);
				verboffset.put(stemmedverb, freq+"\t"+cummulateoffset);
			}else
			{
	//			verboffset.put(stemmedverb, 1+"\t"+offset);
				verboffset.put(stemmedverb, 1+"\t"+productoffset);
			}
		}
		
		Iterator<String> verbs=verboffset.keySet().iterator();
		while (verbs.hasNext())
		{
			String verb=verbs.next();
			String line=verboffset.get(verb);
			System.out.println(verb+"\t"+line);
		}
		System.out.println(lines.length);
	}

}
